using System;
using System.Windows.Forms;
using Microsoft.Practices.CompositeUI.SmartParts;
using Microsoft.Practices.CompositeUI;
using Reflector;

namespace DeblectorAddIn.WorkItems
{
    [SmartPart]
    public partial class GenericWindowHost : UserControl,IWindow
    {
        private RootWorkItem _workItem;
        [ServiceDependency]
        public RootWorkItem WorkItem
        {
            set { _workItem = value; }
        }
        
        public bool _visible = true;
        private string _hostingWorkspace;
        public new bool Visible
        {
            get { return _visible; }
            set { 
                    _visible = value;
                    if (false == value)
                    {
                        _workItem.Workspaces[_hostingWorkspace].Close(this);
                    }
            }
        }
        public GenericWindowHost(Control content,string HostingWorkspace)
        {
            InitializeComponent();
            _hostingWorkspace = HostingWorkspace;
            _content = content;
            if (null != _content)
            {
                _content.Visible = true;
                DoLayout();
            }
        }
        public void DoLayout()
        {
            if( !Controls.Contains(_content) )
                Controls.Add(_content);
            _content.Dock = DockStyle.Fill;
        }
        #region IWindow Members
        string _caption="";
        public void Focus()
        {
            base.Focus();
        }

        public string Caption
        {
            get { return _caption; }
            set { _caption = value; }
        }
        Control _content;
        public Control Content
        {
            get { return _content; }
            set { _content = value; DoLayout(); }
        }

        #endregion

        private void GenericWindowHost_Enter(object sender, EventArgs e)
        {

        }
    }
}
